package com.sx.medicinecard.config;

import com.sx.medicinecard.handler.JwtTokenAdminHandler;
import com.sx.medicinecard.handler.LoginUserRoleHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private JwtTokenAdminHandler jwtTokenAdminHandler;

    @Autowired
    private LoginUserRoleHandler loginUserRoleHandler;

    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("自定义拦截器开始");
        registry.addInterceptor(jwtTokenAdminHandler)
                .addPathPatterns("/sxChannelInfo/**")
                .addPathPatterns("/sxOrderInfo/**")
                .addPathPatterns("/sxLinkInfo/**")
                .addPathPatterns("/sxConsumeRecordInfo/**")
                .addPathPatterns("/sxConsumeRecordInfo/**")
                .addPathPatterns("/sxUserInfo/**")
                .addPathPatterns("/sxOrderInfo/**")
                .addPathPatterns("/sxUserLogin/userInfo")
                .excludePathPatterns("/sxCodeInfo/**")
        ;

        registry.addInterceptor(loginUserRoleHandler)
//                .addPathPatterns("/sxChannelInfo/**")
//                .addPathPatterns("/sxOrderInfo/**")
                .addPathPatterns("/sxLinkInfo/**")
                .addPathPatterns("/sxConsumeRecordInfo/**")
                .addPathPatterns("/sxConsumeRecordInfo/**")
 //               .addPathPatterns("/sxUserInfo/**")
                .excludePathPatterns("/sxUserLogin/**")
                .excludePathPatterns("/sxCodeInfo/**");
    }
}
